package com.eeboot.vo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class LogCountGroup implements Serializable {
    private String profile;
    private Long windowEnd;
    private List<CountGroupData> group = new ArrayList<>();

    public LogCountGroup(String profile, Long windowEnd) {
        this.profile = profile;
        this.windowEnd = windowEnd;
    }

    public void putLogCount(LogCount logCount) {
        group.add(new CountGroupData(logCount.windowSize, logCount.count));
    }

    public String toJsonString() {
        StringBuilder sb = new StringBuilder()
                .append("{")
                .append("\"profile\":")
                .append("\"")
                .append(profile)
                .append("\"")
                .append(",")
                .append("\"windowEnd\":")
                .append(windowEnd)
                .append(",")
                .append("\"group\":");

        sb.append("[");
        for (int i = 0; i < group.size(); i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(group.get(i).toJsonString());
        }
        sb.append("]");
        sb.append("}");
        return sb.toString();
    }

    @Override
    public String toString() {
        return toJsonString();
    }

    public String getProfile() {
        return profile;
    }

    public void setProfile(String profile) {
        this.profile = profile;
    }

    public Long getWindowEnd() {
        return windowEnd;
    }

    public void setWindowEnd(Long windowEnd) {
        this.windowEnd = windowEnd;
    }

    public List<CountGroupData> getGroup() {
        return group;
    }

    public void setGroup(List<CountGroupData> group) {
        this.group = group;
    }

    private static class CountGroupData {
        private Long windowSize;
        private Long count;

        public CountGroupData(Long windowSize, Long count) {
            this.windowSize = windowSize;
            this.count = count;
        }

        public String toJsonString() {
            return new StringBuilder()
                    .append("{")
                    .append("\"windowSize\":")
                    .append(windowSize)
                    .append(",")
                    .append("\"count\":")
                    .append(count)
                    .append("}")
                    .toString()
                    ;
        }
    }
}
